package com.yikaiye.android.yikaiye.ui.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.DataBindingHolder;
import com.yikaiye.android.yikaiye.R;
import com.yikaiye.android.yikaiye.databinding.ItemPhoneNumBinding;
import com.yikaiye.android.yikaiye.model.UserModel;
import com.yikaiye.android.yikaiye.utils.CommonUtil;

public class PhoneNumberAdapter extends BaseQuickAdapter<UserModel.MergeTelModel, DataBindingHolder<ItemPhoneNumBinding>> {

    private final Context context;

    public PhoneNumberAdapter(Context context) {
        this.context = context;
    }

    @SuppressLint("NotifyDataSetChanged")
    @Override
    protected void onBindViewHolder(@NonNull DataBindingHolder<ItemPhoneNumBinding> itemPhoneNumBindingDataBindingHolder, int i, @Nullable UserModel.MergeTelModel model) {
        ItemPhoneNumBinding binding = itemPhoneNumBindingDataBindingHolder.getBinding();
        if (model != null) {
            if (getItemCount() > 1) {
                binding.phoneNoTv.setText(context.getString(R.string.phone_number_no, i + 1));
            } else {
                binding.phoneNoTv.setText(context.getString(R.string.phone_number));
            }
            binding.defTagTv.setVisibility(i == 0 ? View.VISIBLE : View.GONE);
            binding.phoneTv.setText(CommonUtil.checkText(model.getTelNumber()));
//            itemPhoneNumBindingDataBindingHolder.itemView.setOnClickListener(view -> {
//                Bundle bundle = new Bundle();
//                JumpIntent.jump((Activity) context, SetDefPhoneActivity.class, bundle);
//            });
        }
    }

    @NonNull
    @Override
    protected DataBindingHolder<ItemPhoneNumBinding> onCreateViewHolder(@NonNull Context context, @NonNull ViewGroup viewGroup, int i) {
        return new DataBindingHolder<>(R.layout.item_phone_num, viewGroup);
    }
}
